package com.fenghongzhang.day009;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class MySqlHelp extends SQLiteOpenHelper {

    private static final String TAG = "MySqlHelp";

    /**
     *
     * @param context 上下文
     * @param name 数据库的名字 ****.db
     * @param factory null
     * @param version 2  变化,会调用onUpgrade方法
     */
    public MySqlHelp(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    /**
     * 创建数据库自动条用
     * @param db  操作数据
     * 执行一次
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i(TAG, "onCreate: ");
        db.execSQL("create table student (id integer primary key autoincrement ,name varchar(20))");
    }

    /**
     * 更新自动调用
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "onUpgrade: ");
        db.execSQL("create table student2 (id integer primary key autoincrement ,name varchar(20))");
    }
}
